package com.zzty.taskapp.servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.codehaus.jackson.map.ObjectMapper;

import com.zzty.taskapp.entity.Clazz;
import com.zzty.taskapp.service.ClassService;
import com.zzty.taskapp.serviceImpl.ClassServiceImpl;

@WebServlet(name="ClazzServlet",urlPatterns="/ClazzServlet")
public class ClazzServlet extends HttpServlet {

	
	
	
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		ClassService cs=new ClassServiceImpl();
		List<Clazz> clazzs=cs.getAllClazz();
		ObjectMapper mapper = new ObjectMapper();
		String json = mapper.writeValueAsString(clazzs);
		PrintWriter out = resp.getWriter();
		out.println(json);
		out.flush();
		out.close();
	}

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
	}
	

}
